package org.achartengine.internal.chart;

import android.graphics.Canvas;
import android.graphics.Paint;
import org.achartengine.internal.renderer.DialRenderer;

/* loaded from: classes2.dex */
public class d extends a {
    private static final int a = 10;
    private static final int b = 10;
    private org.achartengine.internal.model.a c;
    private DialRenderer d;

    @Override // org.achartengine.internal.chart.a
    public int a(int i) {
        return 10;
    }

    public d(org.achartengine.internal.model.a aVar, DialRenderer dialRenderer) {
        this.c = aVar;
        this.d = dialRenderer;
    }

    @Override // org.achartengine.internal.chart.a
    public void a(Canvas canvas, int i, int i2, int i3, int i4, Paint paint) {
        paint.setAntiAlias(this.d.q());
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(this.d.g());
        int u = this.d.u();
        if (this.d.l() && u == 0) {
            u = i4 / 5;
        }
        int i5 = u;
        int i6 = i + i3;
        int c = this.c.c();
        String[] strArr = new String[c];
        for (int i7 = 0; i7 < c; i7++) {
            this.c.b(i7);
            strArr[i7] = this.c.c(i7);
        }
        int a2 = this.d.m() ? a(canvas, this.d, strArr, i, i6, i2, i3, i4, i5, paint, true) : i5;
        int i8 = (i2 + i4) - a2;
        a(this.d, canvas, i, i2, i3, i4, paint, false, 0);
        double min = Math.min(Math.abs(i6 - i), Math.abs(i8 - i2));
        Double.isNaN(min);
        double t = this.d.t();
        Double.isNaN(t);
        int i9 = (int) (min * 0.35d * t);
        int i10 = (i + i6) / 2;
        int i11 = (i8 + i2) / 2;
        float f = i9;
        float f2 = f * 0.9f;
        float f3 = f * 1.1f;
        double A = this.d.A();
        double C = this.d.C();
        double y = this.d.y();
        double z = this.d.z();
        if (!this.d.B() || !this.d.D()) {
            int a3 = this.d.a();
            for (int i12 = 0; i12 < a3; i12++) {
                double b2 = this.c.b(i12);
                if (!this.d.B()) {
                    A = Math.min(A, b2);
                }
                if (!this.d.D()) {
                    C = Math.max(C, b2);
                }
            }
        }
        if (A == C) {
            A *= 0.5d;
            C *= 1.5d;
        }
        double d = A;
        double d2 = C;
        paint.setColor(this.d.f());
        double E = this.d.E();
        double F = this.d.F();
        if (E == Double.MAX_VALUE) {
            E = (d2 - d) / 30.0d;
        }
        double d3 = E;
        double d4 = F == Double.MAX_VALUE ? (d2 - d) / 10.0d : F;
        double d5 = f3;
        a(canvas, d, d2, y, z, i10, i11, d5, i9, d3, paint, false);
        double d6 = f2;
        a(canvas, d, d2, y, z, i10, i11, d5, d6, d4, paint, true);
        int a4 = this.d.a();
        for (int i13 = 0; i13 < a4; i13++) {
            double a5 = a(this.c.b(i13), y, z, d, d2);
            paint.setColor(this.d.a(i13).b());
            a(canvas, a5, i10, i11, d6, this.d.f(i13) == DialRenderer.Type.ARROW, paint);
        }
        a(canvas, this.d, strArr, i, i6, i2, i3, i4, a2, paint, false);
    }

    private double a(double d, double d2, double d3, double d4, double d5) {
        return Math.toRadians(d2 + (((d - d4) * (d3 - d2)) / (d5 - d4)));
    }

    private void a(Canvas canvas, double d, double d2, double d3, double d4, int i, int i2, double d5, double d6, double d7, Paint paint, boolean z) {
        double d8 = d;
        while (d8 <= d2) {
            double a2 = a(d8, d3, d4, d, d2);
            double sin = Math.sin(a2);
            double cos = Math.cos(a2);
            float f = i;
            int round = Math.round(((float) (d6 * sin)) + f);
            float f2 = i2;
            int round2 = Math.round(((float) (d6 * cos)) + f2);
            int round3 = Math.round(f + ((float) (sin * d5)));
            int round4 = Math.round(f2 + ((float) (cos * d5)));
            float f3 = round;
            float f4 = round2;
            double d9 = d8;
            canvas.drawLine(f3, f4, round3, round4, paint);
            if (z) {
                paint.setTextAlign(Paint.Align.LEFT);
                if (round <= round3) {
                    paint.setTextAlign(Paint.Align.RIGHT);
                }
                String str = d9 + "";
                long j = (long) d9;
                if (Math.round(d9) == j) {
                    str = j + "";
                }
                canvas.drawText(str, f3, f4, paint);
            }
            d8 = d9 + d7;
        }
    }

    private void a(Canvas canvas, double d, int i, int i2, double d2, boolean z, Paint paint) {
        float[] fArr;
        double radians = d - Math.toRadians(90.0d);
        int sin = (int) (Math.sin(radians) * 10.0d);
        int cos = (int) (Math.cos(radians) * 10.0d);
        int sin2 = ((int) (Math.sin(d) * d2)) + i;
        int cos2 = ((int) (Math.cos(d) * d2)) + i2;
        if (z) {
            double d3 = 0.85d * d2;
            int sin3 = ((int) (d3 * Math.sin(d))) + i;
            int cos3 = ((int) (d3 * Math.cos(d))) + i2;
            float f = sin2;
            float f2 = cos2;
            fArr = new float[]{sin3 - sin, cos3 - cos, f, f2, sin3 + sin, cos3 + cos};
            float strokeWidth = paint.getStrokeWidth();
            paint.setStrokeWidth(5.0f);
            canvas.drawLine(i, i2, f, f2, paint);
            paint.setStrokeWidth(strokeWidth);
        } else {
            fArr = new float[]{i - sin, i2 - cos, sin2, cos2, i + sin, i2 + cos};
        }
        a(canvas, fArr, paint, true);
    }

    @Override // org.achartengine.internal.chart.a
    public void a(Canvas canvas, org.achartengine.internal.renderer.b bVar, float f, float f2, int i, Paint paint) {
        canvas.drawRect(f, f2 - 5.0f, f + 10.0f, f2 + 5.0f, paint);
    }
}
